package com.example.financeapi.entity.vo;

import com.alibaba.fastjson.JSONObject;

/**
 * (通一返回前端的返回视图对象)
 * (HTTP 请求返回的最外层对象)
 */
public class ResultVo <T> {

    /** 错误码 */
    private Integer code;

    /** 提示信息 */
    private String msg;

    /** 数据 */
    private T data;

    /**无参构造*/
    public ResultVo() {
    }

    /**两参构造*/
    public ResultVo(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String failed(Integer code, String message) {
        return JSONObject.toJSONString(new ResultVo(code, message));
    }

    //获取错误码
    public Integer getCode() {
        return code;
    }

    //设置错误码
    public void setCode(Integer code) {
        this.code = code;
    }

    //获取提示消息
    public String getMsg() {
        return msg;
    }

    //设置提示消息
    public void setMsg(String msg) {
        this.msg = msg;
    }

    //获取数据
    public T getData() {
        return data;
    }

    //设置数据
    public void setData(T data) {
        this.data = data;
    }
}
